// 文件路径: com.huaxin.device.controller.DeviceAlarmConfigController.java
package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.DeviceAlarmConfigCreateReqDTO;
import com.huaxin.device.dto.request.DeviceAlarmConfigPageListReqDTO;
import com.huaxin.device.dto.request.DeviceAlarmConfigUpdateReqDTO;
import com.huaxin.device.models.DeviceAlarmConfig;
import com.huaxin.device.service.DeviceAlarmConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "设备报警配置")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/alarmConfig")
public class DeviceAlarmConfigController {

    private final DeviceAlarmConfigService service;

    @Operation(summary = "创建设备报警配置", description = "创建设备报警配置")
    @PostMapping("/create")
    public ResponseResult<DeviceAlarmConfig> create(@RequestBody @Valid DeviceAlarmConfigCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取设备报警配置", description = "根据ID获取设备报警配置")
    @GetMapping("/get")
    public ResponseResult<DeviceAlarmConfig> get(
            @Parameter(description = "配置ID", example = "c123e456-789a-bcde-f012-3456789abcde")
            @RequestParam(value = "id", required = true) String id) {
        DeviceAlarmConfig config = service.getByConfigId(id);
        return ResponseResult.ok(config);
    }

    @Operation(summary = "更新设备报警配置", description = "更新设备报警配置")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid DeviceAlarmConfigUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除设备报警配置", description = "删除设备报警配置（需处于禁用状态）")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(
            @Parameter(description = "配置ID", example = "c123e456-789a-bcde-f012-3456789abcde")
            @PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "启用设备报警配置", description = "启用设备报警检测")
    @GetMapping("/enable")
    public ResponseResult<String> enable(
            @Parameter(description = "配置ID", example = "c123e456-789a-bcde-f012-3456789abcde")
            @RequestParam(value = "id", required = true) String id) {
        return service.enable(id);
    }

    @Operation(summary = "禁用设备报警配置", description = "禁用设备报警检测")
    @GetMapping("/disable")
    public ResponseResult<String> disable(
            @Parameter(description = "配置ID", example = "c123e456-789a-bcde-f012-3456789abcde")
            @RequestParam(value = "id", required = true) String id) {
        return service.disable(id);
    }

    @Operation(summary = "分页查询设备报警配置", description = "分页查询设备报警配置列表")
    @PostMapping("/page")
    public ResponseResult<IPage<DeviceAlarmConfig>> pageQuery(@RequestBody @Valid DeviceAlarmConfigPageListReqDTO in) {
        return service.pageQuery(in);
    }
}